package cn.bearspark.happening.provider.dao.key;

import cn.bearspark.framework.redis.starter.buffer.hash.un.RedisHashBufferKeyBuilder;
import cn.bearspark.framework.redis.starter.key.RedisKeyBuilder;
import org.springframework.stereotype.Component;

/**
 * 动态模块中 redis 缓存键的构造器
 *
 * @author f
 */
@Component
public class HappeningBufferKeyBuilder extends RedisKeyBuilder implements RedisHashBufferKeyBuilder {

    /**
     * 动态信息 的缓存的键的前缀
     */
    private static final String HAPPENING_INFO = "happeningInfo";

    /**
     * 用户及其关注者发布的动态的 id 的缓存的键的前缀
     */
    private static final String HAPPENING_PAGE_INFO = "happeningPageInfo";

    /**
     * 用户及其关注者发布的动态的总数的缓存的键的前缀
     */
    private static final String HAPPENING_TOTAL_INFO = "happeningTotalInfo";

    /**
     * 用户分页查询动态信息的偏移量 的缓存的键的前缀
     */
    private static final String PAGE_OFFSET = "pageOffset";

    /**
     * 用户发布的动态的 id 的缓存的键的前缀
     */
    private static final String USER_HAPPENING_PAGE_INFO = "userHappeningPageInfo";

    /**
     * 动态的图片的缓存的键的前缀
     */
    private static final String HAPPENING_IMG_INFO = "happeningImgInfo";

    @Override
    public String buildHashBufferKey(long id) {
        return super.getPrefix() + HAPPENING_INFO + super.getSplitItem() + id;
    }

    public String buildHappeningPageInfoKey(long userId) {
        return super.getPrefix() + HAPPENING_PAGE_INFO + super.getSplitItem() + userId;
    }

    public String getHappeningPageInfoKeyPrefix() {
        return super.getPrefix() + HAPPENING_PAGE_INFO + super.getSplitItem();
    }

    public String buildHappeningTotalInfoKey(long userId) {
        return super.getPrefix() + HAPPENING_TOTAL_INFO + super.getSplitItem() + userId;
    }

    public String buildPageOffsetKey(long userId) {
        return super.getPrefix() + PAGE_OFFSET + super.getSplitItem() + userId;
    }

    public String getPageOffsetKeyPrefix() {
        return super.getPrefix() + PAGE_OFFSET + super.getSplitItem();
    }

    public String buildUserHappeningPageInfoKey(long userId, int visCode) {
        return super.getPrefix() + USER_HAPPENING_PAGE_INFO +
               super.getSplitItem() + userId +
               super.getSplitItem() + visCode;
    }

    public String buildUserHappeningPageInfoKeyPrefix(long userId) {
        return super.getPrefix() + USER_HAPPENING_PAGE_INFO +
               super.getSplitItem() + userId +
               super.getSplitItem();
    }

    public String buildHappeningImgKey(long happeningId) {
        return super.getPrefix() + HAPPENING_IMG_INFO + super.getSplitItem() + happeningId;
    }
}
